package com.example.demo.principle.component;

import com.example.demo.principle.model.Dog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class BeanLifeComponet implements BeanNameAware {
//    @Autowired
    private Dog singletonDog;
    public BeanLifeComponet() {
        log.info("执行构造函数");
    }
    //setter注入
//    @Autowired
//    public void setSingletonDog(Dog singletonDog) {
//        this.singletonDog = singletonDog;
//        log.info("属性注入");
//    }
    @Autowired
    public BeanLifeComponet(Dog singletonDog) {
        this.singletonDog = singletonDog;
        log.info("执行构造方法");
    }

    @PostConstruct
    public void init() {
        log.info("执行init 方法");
    }

    public void use() {
        log.info("使用bean");
    }
    @PreDestroy
    public void destroy() {
        log.info("执行PreDestroy 方法");
    }

    @Override
    public void setBeanName(String name) {
       log.info("执行setBeanName ： " + name);
    }
}
